﻿using BookStore.Application.User;
using BookStore.EntityFrameworkCore;
using BookStore.Web.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

namespace BookStore.Web.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;
        private readonly ITestService _testService;
        private readonly BookStoreDbContext _dbContext;
        private readonly IUserAppService _userAppService;

        public HomeController(ILogger<HomeController> logger
            , ITestService testService
            , BookStoreDbContext dbContext
            , IUserAppService userAppService)
        {
            _logger = logger;

            _testService = testService;

            _dbContext = dbContext;

            _userAppService = userAppService;
        }

        public async Task<IActionResult> Index()
        {
            ViewBag.Name = _testService.GetName();
            ViewBag.User = _dbContext.Users.FirstOrDefault();
            ViewBag.UserInfo = await _userAppService.GetAsync("3160410046", "123456");
            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
